home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls036.1.Z / tls036.1 / usr / lib / scosmt / scriptlib / base / tarcomp / tarcomp
Encoding:
Text File  |  1992-09-15  |  1.2 KB  |  43 lines

  1. #
  2. # tarcomp:  Determines whether the system 'tar' is capable of decompressing.
  3. # files automatically.  The command tar is used unless another is
  4. # specified in the variable TARPROG.
  5. # Returns 'true' (0) if the tar program can decompress, 'fail' if it cannot.
  6. #
  7. tarcomp() {
  8.  
  9.     # Set TARPROG to default of tar if not set.
  10.     : ${TARPROG:=tar}
  11.     tctmp=/tmp/tc$$        # Name for tmp files.
  12.  
  13.     # Eminently compressible data to go into file. (60 'a's)
  14.     _ptrn="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  15.  
  16.     echo ${_ptrn} | compress -F > $tctmp.A    # Compress data.
  17.  
  18.     # Tar to an archive file, with headers set to indicate compression.
  19.     ${TARPROG} Cf $tctmp.T  $tctmp.A  2>/dev/null || {
  20.     rm -rf $tctmp.* 
  21.     return 1
  22.     }
  23.  
  24.     # Now restore original file from archive - it should automagically
  25.     # be decompressed.
  26.     rm -f $tctmp.A
  27.     ${TARPROG} xf $tctmp.T  2>/dev/null  || {
  28.     rm -rf $tctmp.*
  29.     return 1
  30.     }
  31.  
  32.     # Compare it to the original data.
  33.     echo ${_ptrn} | cmp -s - $tctmp.A  2>/dev/null || {
  34.     rm -rf $tctmp.*
  35.     return 1
  36.     }
  37.  
  38.     # If we got here, the two compared equal, which
  39.     # implies that the compress/decompress cycle worked.
  40.     rm -rf $tctmp.*
  41.     return 0
  42. }
  43.